﻿using System.Collections.Generic;
using ITM495.OOExamples.Core.Logger;

namespace ITM495.OOExamples.Core.Shapes
{
    public class ShapeController: IController
    {
        private ILogger logger = LogManager.GetLogger();

        public int NumCircles { get; set; }
        public int NumRectangles { get; set; }
        public List<Shape> Shapes { get; set; }

        public ShapeController()
        {
            Shapes = new List<Shape>();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="options"></param>
        public void Run(Options options)
        {
            SetOptions(options);

            logger.Log("Welcome to the Shape Runner!!");
            logger.Log("--------------------------------------------------------");

            logger.Log("We will now draw: ");
            logger.Log("\t{0}-Circles", NumCircles);
            logger.Log("\t{0}-Rectangles", NumRectangles);
            logger.Log("-------------------------------------------------------");
           

            CreateCircles();
            CreateRectangles();

            foreach (var s in Shapes)
            {
                s.Draw(logger);
            }

            logger.Log("---------- Shape Program Complete ---------------------");
           
        }

        private void CreateRectangles()
        {
            for (int i = 0; i < NumRectangles; i++)
            {
                Shapes.Add(new Rectangle(0, 0));
            }
        }

        private void CreateCircles()
        {
            for (int i = 0; i < NumCircles; i++)
            {
                Shapes.Add(new Circle(0,0,15));
            }
        }

        private void SetOptions(Options options)
        {
            NumCircles = options.ContainsKey("-c") ? int.Parse(options["-c"]) : 0;
            NumRectangles = options.ContainsKey("-r") ? int.Parse(options["-r"]) : 0;
        }
    }
}